package com.liangliang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liangliang.pojo.ProductInfo;
import com.liangliang.service.ProductInfoService;
import com.liangliang.mapper.ProductInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
* @author 13172
* @description 针对表【product_info】的数据库操作Service实现
* @createDate 2024-07-20 21:01:59
*/
@Service
public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, ProductInfo>
    implements ProductInfoService{


    @Autowired
    private ProductInfoMapper productInfoMapper;

    @Override
    public void generateAndInsertData(int numberOfRecords) {
        List<ProductInfo> productInfoList = new ArrayList<>();
        Random random = new Random();
        String[] productNames = {"Laptop", "Smartphone", "Tablet", "Monitor", "Keyboard", "Mouse", "Printer", "Headphones"};
        String[] extendInfos = {"High performance", "New model", "Discounted", "Limited edition", "Best seller"};

        for (int i = 0; i < numberOfRecords; i++) {
            ProductInfo productInfo = new ProductInfo();
            productInfo.setProductId((long) (i + 1));
            productInfo.setProductName(productNames[random.nextInt(productNames.length)]);
            productInfo.setExtendInfo(extendInfos[random.nextInt(extendInfos.length)]);
            productInfoList.add(productInfo);
        }

        productInfoMapper.insertBatch(productInfoList);
    }
}




